﻿#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#define MAXN 64
using namespace std;

int N, LEN, M;   //LEN为原始棍子长度, M为原始棍子数量 
int S[MAXN], MK[MAXN];
bool FLAG;
 
int cmp(int a, int b)
{
    return a > b;
}

void dfs(int k, int sum, int cnt)
{
  printf("k = %d,sum = %d,cnt = %d\n",k,sum,cnt);
    if (cnt == M)
        FLAG = true;
    else if (sum == LEN)
        dfs(0, 0, cnt+1);
    else
        for (int pre = -1, i = k; i < N; i++)
            if (!MK[i] && S[i]!=pre && S[i]+sum<=LEN)
            {
                pre = S[i];
                MK[i] = true;
                printf("i = %d, sum = %d,S[i] = %d\n",i,sum,S[i]); 
                dfs(i+1, sum+S[i], cnt);
                MK[i] = false;
                if (k == 0 || FLAG)
                    return;
            }
}

int main()
{

  freopen("1011in.txt","r",stdin); 
  freopen("1011out.txt","w",stdout); 

  int sum, i;
    
  while (scanf("%d", &N) != EOF && N)
    {
      FLAG = false;
      sum = 0;
      for (i = 0; i < N; i++)
        {
          scanf("%d", &S[i]);
          sum += S[i];
        }

      printf("sum = %d\n",sum);
      
      sort(S, S+N, cmp);

      for (i = 0; i < N; i++)
        {
          printf("%d ",S[i]);
        }
      printf("\n");
      
      for (LEN = S[0]; LEN < sum; LEN++)
        if (sum % LEN == 0)
          {
            M = sum / LEN;
            printf("LEN = %d, M = %d\n",LEN,M); 
            memset(MK, 0, sizeof(MK));
            dfs(0, 0, 0);
            if (FLAG)
              break;
          }
      printf("%d\n", FLAG? LEN : sum);
    }

  fclose(stdin);
  fclose(stdout);
  
  return 0;
}
